﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using Objects.Utility;
using System.IO;
using System.Web;


public partial class BrandingConfiguration : Objects.cSecurePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Settings settings = new Settings();
        string strImagePath = settings.GetKeyValue("Logo");
        if (string.IsNullOrEmpty(strImagePath))
        {
            lnkShowLogo.Visible = false;
        }
        else
        {
            lnkShowLogo.Visible = true;
            lnkShowLogo.Attributes.Add("onClick", "javascript:showPopUp('" + strImagePath + "')");

        }

        strImagePath = settings.GetKeyValue("HomePage");
        if (string.IsNullOrEmpty(strImagePath))
        {
            lnkShowHomeImage.Visible = false;
        }
        else
        {
            lnkShowHomeImage.Visible = true;
            lnkShowHomeImage.Attributes.Add("onClick", "javascript:showPopUp('" + strImagePath + "')");

        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (fuLogoImage.FileContent.Length > 0)
        {
            Settings settings = new Settings();
            string logoUrl = System.Web.HttpContext.Current.Server.MapPath("~") + settings.GetKeyValue("Logo");
            if (File.Exists(logoUrl.Replace("/", @"\")))
            {
                File.Delete(logoUrl);
            }
            fuLogoImage.SaveAs(System.Web.HttpContext.Current.Server.MapPath("~") + "/UpLoadedFiles/Logo" + Path.GetExtension(fuLogoImage.FileName));           
            settings.Add("Logo", "/CMT/UpLoadedFiles/Logo" + Path.GetExtension(fuLogoImage.FileName));
            settings.Save();
        }

        if (fuFieldAdminHomePage.FileContent.Length > 0)
        {           
            Settings settings = new Settings();
            string homeUrl = System.Web.HttpContext.Current.Server.MapPath("~") + settings.GetKeyValue("HomePage");
            if (File.Exists(homeUrl.Replace("/", @"\")))
            {
                File.Delete(homeUrl);
            }
            fuFieldAdminHomePage.SaveAs(System.Web.HttpContext.Current.Server.MapPath("~") + "/UpLoadedFiles/HomePage" + Path.GetExtension(fuFieldAdminHomePage.FileName));
            settings.Add("HomePage", "/CMT/UpLoadedFiles/HomePage" + Path.GetExtension(fuFieldAdminHomePage.FileName));
            settings.Save();
        }
    }
}
